<template>
  <div>
    <el-form
      :model="ruleForm"
      :rules="rules"
      ref="ruleForm"
      class="demo-ruleForm"
    >
      <el-form-item prop="userCode">
        <el-input
          placeholder="请输入用户名"
          clearable
          v-model="ruleForm.userCode"
        >
          <template #prepend><i class="el-icon-user"></i></template>
        </el-input>
      </el-form-item>
      <el-form-item prop="userPassword">
        <el-input
          show-password
          clearable
          placeholder="请输入密码"
          v-model="ruleForm.userPassword"
        >
          <template #prepend><i class="el-icon-lock"></i></template
        ></el-input>
      </el-form-item>
      <el-form-item style="margin-bottom: 0">
        <el-button type="primary" class="submit" @click="submitForm('ruleForm')"
          >登录</el-button
        >
      </el-form-item>
    </el-form>
  </div>
</template>
<script>
export default {
  data() {
    return {
      seeState: false,
      ruleForm: {},
      rules: {
        userCode: [
          { required: true, message: "用户名不能为空", trigger: "blur" },
        ],
        userPassword: [
          {
            required: true,
            message: "密码不能为空",
            trigger: "blur",
          },
          {
            message: "密码格式不正确", //密码长度8至16位，必须符合由数字,大写字母,小写字母,特殊符,至少其中三种类型！(例:1234@abc)
            trigger: "blur",
            pattern:
              /^(?![a-zA-Z]+$)(?![A-Z0-9]+$)(?![A-Z\\W_!@#$%^&*`~()-+=]+$)(?![a-z0-9]+$)(?![a-z\\W_!@#$%^&*`~()-+=]+$)(?![0-9\\W_!@#$%^&*`~()-+=]+$)[a-zA-Z0-9\\W_!@#$%^&*`~()-+=]{8,16}$/,
          },
        ],
      },
    };
  },
  methods: {
    submitForm(formName) {
      this.$refs[formName].validate((valid) => {
        this.$emit("login", valid, this.ruleForm);
      });
    },
  },
};
</script>
<style lang="less" scoped>
:deep(.el-input-group__prepend) {
  padding: 0 8px;
}
:deep(.el-input__inner:focus) {
  border-color: #dcdfe6;
}
:deep(.el-form-item__content) {
  line-height: 28px;
}
.submit {
  width: 100%;
}
</style>
